﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TekaMUD.Engine.Blocks;
using TekaMUD.Engine.Behaviour;

namespace TekaMUD.Engine.ServerTasks
{
	/// <summary>
	/// Refreshes all Agents in the game.
	/// </summary>
	public class RefreshPlayerTask : Task, IRepeatableTask
	{
		private const int FREQUENCY_SECONDS = 2;
		private TimeSpan period;

		public RefreshPlayerTask() : base("Refresh Players")
		{
			period = new TimeSpan(0, 0, FREQUENCY_SECONDS);
		}

		public override void Execute()
		{
			GameEntity[] players = (GameEntity[])EntityManager.GetByType(typeof(Player));

			foreach (Player p in players)
				if (p.Status == PlayerStatus.Active)
					p.Health.UpdateHealth();
		}

		public RepeatableTaskType RepeatType
		{
			get 
			{
				return RepeatableTaskType.Interval;
			}
		}

		public TimeSpan GetNextRunInterval()
		{
			return period;
		}

		public DateTime GetNextRunDate()
		{
			throw new InvalidOperationException();
		}
	}
}